package transfer;

import java.util.ArrayList;

import Itransfer.Itransfer;

public class OracleTransfer implements Itransfer {

    /**
     * show databases of selected database server just need to return the SQL of MySQL
     */
    public String showDatabase() {
        return "show databases";
    }
    /**
     * show all table names of the given database
     */
    public String showTables(String dbname){
        return "select * from tab";
    }
    /**
     * show segment name of the given table
     * user_tab_columns is a system table that records all the columns info of tables
     */
    public String showTitles(String dbname,String tname){
        return "select column_name from  user_tab_columns where table_name="+"'"+tname+"'";
    }
    public String insert(ArrayList<String> dbSeg,ArrayList<String> values,String dbname,String tname){
        StringBuffer segment=new StringBuffer();
        StringBuffer value=new StringBuffer();
        //TODO StringBuffer is more effective！
        for(int i=0;i<dbSeg.size();i++){
            segment.append(dbSeg.get(i));
            value.append(values.get(i));
            if(i!=dbSeg.size()-1){
                segment.append(",");
                value.append(",");
            }
        }
        String sql= "insert into"+" "+tname+"("+segment.toString()+")"+" "+"values("+value.toString()+")";
        System.out.println(sql);
        return sql;
    }

}
